﻿// Copyright © Microsoft Corporation.  All Rights Reserved.
// This code released under the terms of the 
// Microsoft Public License (MS-PL, http://opensource.org/licenses/ms-pl.html.)

using System.Windows.Interactivity;
using System.Windows;
using System.Windows.Controls;

namespace TheOliver.Controls
{
	public class DeepZoom_ZoomIn : TargetedTriggerAction<FrameworkElement>
	{
        MultiScaleImage msi;
        double zoom = 1;

		public double ZoomInValue
		{
			get;
			set;
		}

        private void Zoom(double newzoom, Point p)
        {
            if (newzoom < 0.5)
            {
                newzoom = 0.5;
            }

            msi.ZoomAboutLogicalPoint(newzoom / zoom, p.X, p.Y);
            zoom = newzoom;
        }

		protected override void Invoke(object parameter)
		{
			msi = this.Target as MultiScaleImage;

            Zoom(zoom * ZoomInValue, msi.ElementToLogicalPoint(new Point(.5 * msi.ActualWidth, .5 * msi.ActualHeight)));
		}
	}
}
